//
//  JobDetailInverterTableViewCell.swift
//  GreenDeal
//
//  Created by Moennig Q on 26/12/2022.
//
import UIKit
class JobDetailInverterTableViewCell: TableViewCell {
    let typeImageView = UIImageView()
    var cntLabel: PaddingLabel = {
        let view = PaddingLabel()
        view.paddingTop = 2
        view.paddingBottom = 2
        return view
    }()
    let powerLabel = ContentLabel(R.font.interMedium(size: 13))
    var seriesLabel: PaddingLabel = {
        let view = PaddingLabel()
        view.paddingTop = 2
        view.paddingBottom = 2
        return view
    }()
    let brandLabel = ContentLabel(R.font.interRegular(size: 13))
    let modelLabel = ContentLabel(R.font.interSemiBold(size: 15))
    override func setUpviews() {
        self.contentView.addSubview(typeImageView)
        typeImageView.snp.makeConstraints { make in
            make.top.left.equalTo(2)
            make.height.width.equalTo(40)
        }
        //
        cntLabel.layer.cornerRadius = 10
        cntLabel.clipsToBounds = true
        cntLabel.backgroundColor = UIColor(hexStr: Constant.ThemeColorHexStr)
        cntLabel.textColor = UIColor.white
        cntLabel.setFont(R.font.sfProTextMedium(size: 13))
        self.contentView.addSubview(cntLabel)
        cntLabel.snp.makeConstraints { make in
            make.top.equalTo(typeImageView)
            make.left.equalTo(typeImageView.snp.right).offset(15)
            make.height.width.greaterThanOrEqualTo(0)
        }
        powerLabel.setContentCompressionResistancePriority(.required, for: NSLayoutConstraint.Axis.horizontal)
        powerLabel.setContentHuggingPriority(.required, for: NSLayoutConstraint.Axis.horizontal)
        self.contentView.addSubview(powerLabel)
        powerLabel.snp.makeConstraints { make in
            make.centerY.equalTo(cntLabel)
            make.left.equalTo(cntLabel.snp.right).offset(8)
            make.height.width.greaterThanOrEqualTo(0)
        }
        //series
        seriesLabel.setContentCompressionResistancePriority(.defaultLow, for: NSLayoutConstraint.Axis.horizontal)
        seriesLabel.setContentHuggingPriority(.defaultLow, for: NSLayoutConstraint.Axis.horizontal)
        seriesLabel.layer.cornerRadius = 12
        seriesLabel.clipsToBounds = true
        seriesLabel.backgroundColor = UIColor(hexStr: "#292D321A")
        seriesLabel.textColor = UIColor(hexStr: "#292D3299")
        seriesLabel.setFont(R.font.sfProTextRegular(size: 13))
        seriesLabel.numberOfLines = 0
        self.contentView.addSubview(seriesLabel)
        seriesLabel.snp.makeConstraints { make in
            make.left.equalTo(powerLabel.snp.right).offset(8)
            make.right.lessThanOrEqualToSuperview()
            make.height.width.greaterThanOrEqualTo(0)
            make.centerY.equalTo(cntLabel)
        }
        modelLabel.numberOfLines = 0
        modelLabel.textAlignment = .left
        self.contentView.addSubview(modelLabel)
        modelLabel.snp.makeConstraints { make in
            make.top.equalTo(cntLabel.snp.bottom).offset(10)
            make.left.equalTo(cntLabel)
            make.right.equalTo(-16)
            make.height.greaterThanOrEqualTo(0)
        }
        brandLabel.numberOfLines = 0
        brandLabel.textAlignment = .left
        self.contentView.addSubview(brandLabel)
        brandLabel.snp.makeConstraints { make in
            make.top.equalTo(modelLabel.snp.bottom).offset(6)
            make.left.right.equalTo(modelLabel)
            make.height.greaterThanOrEqualTo(0)
            make.bottom.equalTo(-CREATEJOB_REVIEW_INTERNAL)
        }
    }
    func setData(_ model: InstallationDetailSystemDetailForInverterModel,index: Int){
        self.cntLabel.text = "\(model.number_inverters)x"
        self.brandLabel.text = model.inverter_brand
        self.modelLabel.text = model.inverter_model
        self.seriesLabel.text = model.inverter_series
        if index == 0 {//第一行
            if model.tank_flag {//设置tank
                self.powerLabel.text = ""
                self.typeImageView.image = R.image.swhdetail_systeminfo_tank_icon()
            }else{//设置inverter
                self.powerLabel.text = Tool().formatAmountToStr(amount: "\(model.ac_power)", maximumFractionDigits: 0,minimumFractionDigits: 0)  + "W"
                self.typeImageView.image = R.image.jobdetail_systeminfo_inverter_icon()
            }
        }else{
            if model.tank_flag {//设置tank
                self.powerLabel.text = ""
            }else{
                self.powerLabel.text = Tool().formatAmountToStr(amount: "\(model.ac_power)", maximumFractionDigits: 0,minimumFractionDigits: 0)  + "W"
            }
            self.typeImageView.image = nil
        }
        //主要用于创建Job时，用户改了安装时间导致原来选择的Model变成过期数据
        if model.valid_flag {//有效数据背景是白色
            self.backgroundColor = .white
        }else{//无效数据背景
            self.backgroundColor = UIColor(hexStr: "#ED3E3E1A")
        }
    }
}
